//
//  CityMenuController.m
//  Weather-UI-V1
//
//  Created by lin on 15/7/1.
//  Copyright (c) 2015年 tarena. All rights reserved.
//

#import "CityMenuController.h"
#import "HWDropdownMenu.h"
@interface CityMenuController ()
@property(nonatomic,strong)NSArray *cities;
@end

@implementation CityMenuController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.cities = @[@"Nanjing",@"Hangzhou",@"Shanghai"];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    // Do any additional setup after loading the view.
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cities.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        cell.textLabel.textColor =[UIColor colorWithWhite:1 alpha:0.5];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.font = [UIFont systemFontOfSize:25];
        cell.backgroundColor = [UIColor clearColor];
    }
    
    cell.textLabel.text = self.cities[indexPath.row];
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.citySelected(self.cities[indexPath.row]);
    NSUserDefaults *userDefault  = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:self.cities[indexPath.row] forKey:@"selectedCity"];
    [(HWDropdownMenu*)self.view setHidden:YES];
    
    
}
@end
